package com.hh.pms.controller;

import com.hh.pms.Util.FileConfig;
import com.hh.pms.Util.FileUtil;
import com.ruoyi.common.core.utils.OSUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileConfig fileConfig;
    /**
     * 上传文件存储在本地的根路径
     */
    @Value("${myFile.linuxPath}")
    private String linuxPath;
    @Value("${myFile.winPath}")
    private String winPath;

    @GetMapping("/downloadFiles")
    public void downloadFiles(@RequestParam("file") String file, HttpServletResponse response) {
        if(OSUtils.isWindows()){
            FileUtil.downloadFiles(winPath,file,response);
        }else{
            FileUtil.downloadFiles(linuxPath,file,response);
        }
    }

    @RequestMapping("/RemoteFileDownloader")
    public void RemoteFileDownloader(@RequestParam("file") String file, HttpServletResponse response) {
        FileUtil.RemoteFileDownloader(file, response);
    }

    @PostMapping("/upload")
    public AjaxResult handleFileUpload(MultipartFile file) {
        return fileConfig.ruoyiFileUpload(file);
    }


}
